<?php
class SupplierDataService extends SupplierDSBase
{
	/**
	 * Update status of page
	 *
	 * @access public
	 *
	 * @param int $id: Id of the page
	 *
	 * @return bool
	 *
	 */
	public function updateStatus($id, $status)
	{
		$pageEntity = $this->beforeUpdate($id);
		if ( !is_null($pageEntity)){

			// Set news status
			$SupplierEntity->status = (int) $status;

			// Return result
			return $this->update($SupplierEntity);
		}
	}
	
	/**
	 * 
	 * Get Next Blog Entry
	 * @param int $blogId
	 */
	public function getNextEntry($blogId, $totals = 1)
	{
		if(empty($blogId) || !is_numeric($blogId)) return NULL;
		
		$arrElement = array();
		$arrElement["status"] = SupplierEntity::ACTIVE;

		$arrElement[] = " id > {$blogId}";

		$SupplierDataAccess = new SupplierDataAccess();
		$items = $SupplierDataAccess->getItems($arrElement, " id ASC ", 0 ,$totals);
		
		if(!empty($items))
		{
			if(count($items) == 1)
			{
				return $items[0];
			}
			else 
			{
				return $items;
			}
		}
		
		return NULL;
	}
	
	/**
	 * 
	 * Get Previous Blog Entry
	 * @param int $blogId
	 */
	public function getPreviousEntry($blogId, $totals = 1)
	{
		if(empty($blogId) || !is_numeric($blogId)) return NULL;
		
		$arrElement = array();
		$arrElement["status"] = SupplierEntity::ACTIVE;

		$arrElement[] = " id < {$blogId}";

		$SupplierDataAccess = new SupplierDataAccess();
		$items = $SupplierDataAccess->getItems($arrElement, " id DESC ", 0 ,$totals);
		
		if(!empty($items))
		{
			if(count($items) == 1)
			{
				return $items[0];
			}
			else 
			{
				return $items;
			}
		}
		
		return NULL;
	}
	
}